#pragma once

#include "components.h"
#include "event.h"
#include "models.h"

#include "qbe/src/ecs/ecs.hpp"

#include "../../message/message.hpp"
#include "../../select/select_cmd.hpp"
#include "../../state/state.hpp"
#include "qlib/all.h"

namespace qbe::Stretch {
void exit(ecs::Query query, state::AllModeType enter_mode);
void init(entt::registry& reg, ecs::Commands commands, ecs::Query query);
void update(entt::registry& reg, ecs::Query query, ecs::Bus& bus);
void post(entt::registry& reg, ecs::Commands commands, ecs::Query query, ecs::Bus& bus);
void movePolygonLines(std::vector<std::shared_ptr<double>> slopes, int total_last_index, std::vector<int> line_indexs, int total_size,
                      std::vector<qlib::Vec2d>& points);
void movePointLine(ecs::Query query, std::any ele, double dx, double dy, std::vector<qlib::Vec2d>& points, std::set<int> indexs);
bool stretch(ecs::Query query, double dx, double dy);
bool isNaN(qlib::Vec2d pt);
void clear_event(ecs::Query query);
std::vector<SelectInfo> partSelectToStretch(ecs::Query query, std::unordered_map<entt::entity, select::SelectPartData> selects);
class StretchPlugin : public ecs::Plugin {
 public:
  void build(ecs::App& app) override {
    app.init_resource<StretchModel>(StretchModel{});
    app.init_resource<TempRulerRenderModel>(TempRulerRenderModel{});
    app.init_event<Event>();

    app.add_systems<ecs::stage::Startup>(init);
    app.add_systems<ecs::stage::Update>(update);
    app.add_systems<ecs::stage::PostUpdate>(post);
    app.add_systems<ecs::stage::Last>(clear_event);
  };
};
}  // namespace qbe::Stretch